
#ifndef __PHOTO_VIEW_THUMBNAIL_LAYOUT_H__
#define __PHOTO_VIEW_THUMBNAIL_LAYOUT_H__
#pragma once
#pragma warning(disable:4244)
#pragma warning(disable:4018)

#include <mzfclib.h>
#include "CommonUtility.h"
#include "imaging.h"
#include "PhotoViewerFullViewWindow.h"
#include "PhotoViewThumbnailManager.h"
#include "ImageThumbnailList.h"
#include "PhotoViewerFacility.h"
#include "BottomBar.h"
#define THUMBNIAL_WINDOW_CLOSE                       WM_USER + 112 
struct subThreadThumbData 
{
	ImageThumbnailList *pImageThumbListView;
	FileStats filelist;
	int nTotalRow;
	int nColPerRow;
	StdString currentDirectory;
	HWND hWnd;
	HINSTANCE hInst;
	int nStartIndex;
	DWORD threadID;
	int directoryCount;
};

class CPhotoViewThumbnailLayout : public CMzWndEx
{
	MZ_DECLARE_DYNAMIC(CPhotoViewThumbnailLayout);
public:
	CPhotoViewThumbnailLayout( const TCHAR *photoDirectory, Photo_Setting photoSetting, int cmdType = PV_NORMALE_STARTUP, TCHAR *selectFileName = NULL );
	virtual ~CPhotoViewThumbnailLayout();
	virtual void PaintWin(HDC hdc, RECT* prcUpdate /* = NULL */);
	const TCHAR *MakeFileAbsolutePath( const TCHAR *fileName, TCHAR *absolutePath );
	const TCHAR *GetFileAbsolutePath( Int32 index, TCHAR *absolutePath );
	virtual LRESULT MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam);
	TCHAR* GetCurrentSelectedPhoto()
	{
		return m_currentSelectedPhoto;
	}
protected:
	virtual BOOL OnInitDialog();
 	virtual void OnMzCommand(WPARAM wParam, LPARAM lParam);
	virtual int OnShellHomeKey(UINT message, WPARAM wParam, LPARAM lParam);

//  	virtual void OnLButtonDown(UINT fwKeys, int xPos, int yPos);
//  	virtual void OnLButtonUp(UINT fwKeys, int xPos, int yPos);
//  	virtual void OnMouseMove(UINT fwKeys, int xPos, int yPos);
 //	virtual void OnTimer(UINT_PTR nIDEvent );

private:
	template < class T >
	BOOL _SafeResizeVector( std::vector< T > &v, int newSize )
	{
		v.resize( newSize );
		return newSize == static_cast< int >( v.size() );
	}

	bool _IsRowVisible(Int32 row)
	{
		return m_topRow <= row && row < m_topRow + m_rowPerPage;
	}

	bool _IsThumbVisible( Int32 fileIndex )
	{
		return _IsRowVisible( _FileIndexToRow( fileIndex ) );
	}

	void _SetTopRow( Int32 topRow )
	{
		m_topRow = MAX( 0, MIN( topRow, _TotalRowNum() - m_rowPerPage ) );
	}

	Int32 _FileIndexToRow( Int32 fileIndex ) const
	{
		return fileIndex >= 0 ? fileIndex / m_colPerRow : -1;
	}

	Int32 _FileIndexToCol( Int32 fileIndex ) const
	{
		return fileIndex >=0 ? fileIndex % m_colPerRow : -1;
	}

	Int32 _ThumbIndexToFileIndex( Int32 row, Int32 col ) const
	{
		return row * m_colPerRow + col;
	}

	Int32 _TotalRowNum() const
	{
		return _FileIndexToRow( static_cast< Int32 >( m_fileCount/*m_fileStatsList.size()*/ ) - 1 ) + 1;
	}
	void _DeleteObject()
	{
		for( size_t i = 0; i < m_hBitmapList.size(); ++i )
		{
			for( size_t j = 0; j < m_hBitmapList[ i ].size(); ++j )
			{
				if( m_hBitmapList[ i ][ j ] )
				{
					DeleteObject( m_hBitmapList[ i ][ j ] );
					m_hBitmapList[ i ][ j ] = NULL;
				}
			}
		}
	}
	void _ClearAllThumb();
	BOOL _CreateVector();
	void _RefreshLayoutContent( HDC hdc );	
	void _UpdateThumbs( HDC hdc, int row, int col, const TCHAR *imageFileName );
	void _RefreshLayoutContent();
	void _UpdateThumbs( int row, int col, const TCHAR *imageFileName );
	void _SetTitle( const TCHAR *title );
	void _SetReturnButton();
	void _SetSlidePanel();
	void _SetImageList();
	void _SetSlideShowButton();	
//	std::vector< std::vector< CUiMzPanel* > > m_imageFrames;
	std::vector< std::vector< HBITMAP > >m_hBitmapList;
	void _RefreshFileStats();
	void _SetTakePhotoReturnButton();
	void _SetSelectPhotoReturnButton();
	void _OnSelectItem( int index );
	void _RefreshDirectoryListItem();
	void _ResetThumbnailView();
	void _DrawNoPhotoView( HDC hdc, RECT* prcUpdate  );
	void _ResetDisplay();
	void _OnReturnBtn();
	void _OnSlideShowBtn();
	void _UpdateThumbBg( ImageThumbnailListItem *pItem,int index );
	int _AccMessage( WPARAM wParam );
	void _SendScreenRotateMsg( int screenStatus );
private:
	int m_cmdType;
	int m_rowPerPage;
	int m_colPerRow;
	int m_topRow;
	int m_oldTopRow;
	int m_currSelectRow;
	int m_currSelectCol;
	
	int m_currSelectFile;
// 	IImage *m_pImage;
// 	IImagingFactory *m_pImagingFactory;

	bool m_bLButtonDown;

	TCHAR m_currPhotoDirectory[ MAX_PATH ];
	const TCHAR *m_parentPhotoDirectory;
	FileStats m_fileStatsList;
//	UiPanel m_titlePanel;
//	UiTitleBar m_titleBar;
//	UiPanel m_slidePanel;
// 	BottomBar m_slidePanel;
//jdhuang 20120711
	UiToolbar_Text m_slidePanel;

//jdhuang  20120716
	UiButton_Image m_uiReturnButton;
//	UiImageListCtl m_uiImageListCtl;
//	CPhotoViewerFullViewWindow *m_pFullViewWin;	
//	UiTransBmpButton m_uiSlideShowButton;
	UiButton_Image m_uiSlideShowButton;
// 	UiBmpTextButton m_uiSlideShowButton;
	int m_prevFileSize;
	/*CUiImageThumbnailView*/ImageThumbnailList m_uiImageThumbnailView;
	BOOL m_bHasDeletePhoto;

	subThreadThumbData *m_subThreadThumbData;
	HANDLE m_subThread;
	UiTransBmpButton m_takePhotoReturnBtn;

	TCHAR m_currentSelectedPhoto[MAX_PATH];
	UiButton_Image m_selectPhotoReturnBtn;

	UiPicture m_noPhotoAlbum;	
	UiPicture m_noCamera;
	UINT m_nWnShell;
	HINSTANCE m_hInst;
	int m_directoryCount;
	int m_fileCount;
	HBITMAP m_photoHBitmap;
	PhotoViewerFacility m_photoViewerFacility;
	SubThreadData *m_subThreadData;

	Photo_Setting m_photoSetting;
// 	HBITMAP m_errorBitmap;
	ImagingHelper m_downImage;
	ImagingHelper m_slideshowImage;
	ImagingHelper m_takephotoImage;
	BOOL m_bChangeDisplay;
	BOOL m_bActive;
	int m_screenStatus;
	BOOL m_bAccClosed;
	BOOL m_bExit;
	UiPicture m_ThumbnailLayoutBkWin;
public:
//jdhuang 20120716
	HDC				m_hBakDC;
	HBITMAP			m_hBitmapBakDC;
	ImagingHelper	*m_VideoMainBG;
	BOOL InitImages();
//	UiPicture m_MainBkWin;
};

#endif
